package xin.lhuo.we.server.dao;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Component;
import xin.lhuo.we.server.entity.Weather;

/**
 * @author Lhuo
 * @date 2019/5/24 10:04
 */
@Mapper
@Component
public interface WeatherMapper {

    @Insert("insert into we_weather (ip,date,city,info) values(#{ip},#{date},#{city},#{info})")
    void saveWeather(Weather weather);

    @Select("select * from we_weather where ip=#{ip} and date=#{date}")
    @Results(id = "weather",
            value = {
            @Result(column = "id",property = "id",javaType = Integer.class,jdbcType = JdbcType.INTEGER),
            @Result(column = "ip",property = "ip",javaType = String.class,jdbcType = JdbcType.VARCHAR),
            @Result(column = "date",property = "date",javaType = String.class,jdbcType = JdbcType.VARCHAR),
            @Result(column = "city",property = "city",javaType = String.class,jdbcType = JdbcType.VARCHAR),
            @Result(column = "info",property = "info",javaType = String.class,jdbcType = JdbcType.VARCHAR),
    })
    Weather getWeatherByIpAndDate(@Param("ip")String ip,@Param("date") String date);

    @Select("select * from we_weather where city=#{city} and date=#{date}")
    @ResultMap("weather")
    Weather getWeatherByCityAndDate(@Param("city")String city,@Param("date")String date);
}
